## Project: pyEnkido
## Module: Graphics
## Author: Salwan

# Utilities for drawing stuff

import pygame
import math
import math_utils

def linear_interpolate_color(color1, color2, delta):
    return (math_utils.linear_interpolate(color1[0], color2[0], delta),
            math_utils.linear_interpolate(color1[1], color2[1], delta),
            math_utils.linear_interpolate(color1[2], color2[2], delta))

def draw_vertical_gradient_rect(surface, rect, top_color, bottom_color, levels):
    step = (rect.bottom - rect.top) / levels
    if step < 1:
        return
    for i in range(0, levels):
        r = pygame.Rect(rect.left, rect.top + (i * step), rect.width, step)
        delta = float(i) / float(levels)
        c = linear_interpolate_color(top_color, bottom_color, delta)
        pygame.draw.rect(surface, c, r)